<template>
  <div class="page-one">
    <Header title="首页"></Header>
    <back-top></back-top>
    <div class="plot-wrapper">
      <div class="search">
        <div class="search-wrapper" @click="searchClick">
          <input ref="inputs" type="text" placeholder="请输入歌曲">
          <img class="search-icon" src="../../assets/Image/search@2x.png" alt="">
        </div>
      </div>
    </div>
    <!--图片轮播-->
    <div class="swiper-box">
      <mt-swipe :auto="5000">
        <mt-swipe-item v-for="(item,index) in banner" :key="index">
          <img :src="item.imageUrl" alt="">
          <!--标签-->
          <div class="lable" :style="{background: item.titleColor}">
            {{item.typeTitle}}
          </div>
        </mt-swipe-item>
      </mt-swipe>
    </div>
    <!--推荐歌单-->
    <div class="recommend-songs">
      <div class="recommend-title">
        <div class="title-left">
          <img src="../../assets/Image/song.png" alt="">
          <span>推荐歌单</span>
        </div>
        <span @click="$router.push('/PageTwo')">更多</span>
      </div>
      <div class="song_box">
        <div class="sudoku_item" v-for="(play,index) in result" :key="index" @click="goDetail(play.id)">
          <div class="song_img" :style="{backgroundImage: 'url('+play.picUrl+')'}">
          </div>
          <div class="song_number">
            <Icon style="color: #fff;" type="ios-headset-outline"/>
            <span>{{play.playCount | changeNum}}</span>
          </div>
          <div class="song_text">
            <p>{{play.name}}</p>
          </div>
        </div>
      </div>
    </div>
    <!--独家放送-->
    <div class="sole-send">
      <div class="sole-title">
        <div class="title-left">
          <img src="../../assets/Image/dujia.png" alt="">
          <span>独家放送</span>
        </div>
        <span>更多</span>
      </div>
      <div class="album">
        <Row :gutter="6">
          <!--col的总和为24-->
          <i-col span="12" v-for="(al,mindex) in soleArr" :key="mindex">
            <div class="grid_div" :style="{backgroundImage: 'url(' + al.picUrl + ')'}">
              <div class="video-num">
              </div>
            </div>
            <h3>{{al.name}}</h3>
          </i-col>
        </Row>
      </div>
    </div>
    <!--最新音乐-->
    <div class="new-song">
      <div class="new-title">
        <div class="title-left">
          <img src="../../assets/Image/new.png" alt="">
          <span>最新音乐</span>
        </div>
        <span>更多</span>
      </div>
      <div class="new-album">
        <Row :gutter="6">
          <!--col的总和为24-->
          <i-col span="12" v-for="(song, nindex) in newSong" :key="nindex" @click.native="goSongPlay(song.id,song.song.album.name,song.song.album.artists[0].name,song.song.album.picUrl)">
            <div class="song">
              <div class="index-num">
                <p>{{nindex+1}}</p>
              </div>
              <img :src="song.song.album.picUrl" alt="">
              <div class="song-name">
                <h4>{{song.song.album.name}}</h4>
                <h5>{{song.song.album.artists[0].name}}</h5>
              </div>
            </div>
          </i-col>
        </Row>
      </div>
    </div>
    <!--推荐MV-->
    <div class="recommend-MV">
      <div class="mv-title">
        <div class="title-left">
          <img src="../../assets/Image/tuijian.png" alt="">
          <span>推荐MV</span>
        </div>
        <span @click="$router.push('/moreMV')">更多</span>
      </div>
      <div class="mv-album">
        <Row :gutter="6">
          <!--col的总和为24-->
          <i-col span="12" v-for="(mv,mindex) in mvarr" :key="mindex">
            <div class="grid_div" :style="{backgroundImage: 'url(' + mv.picUrl + ')'}">
              <div class="video-num">
                <Icon style="color: #fff;float: left;padding-left: 10px" type="ios-videocam-outline"/>
                <span>{{mv.playCount | changeNum}}</span>
              </div>
            </div>
            <h3>{{mv.name}}</h3>
            <p>{{mv.artistName}}</p>
          </i-col>
        </Row>
      </div>
    </div>
    <!--主播电台-->
    <div class="radio-station">
      <div class="radio-title">
        <div class="title-left">
          <img src="../../assets/Image/diantai.png" alt="">
          <span>主播电台</span>
        </div>
        <span>更多</span>
      </div>
      <div class="radio-album">
        <Row :gutter="6">
          <!--col的总和为24-->
          <i-col span="12" v-for="(ra, rindex) in radioArr" :key="rindex">
            <div class="song">
              <img :src="ra.picUrl" alt="">
              <div class="song-name">
                <h4>{{ra.name}}</h4>
                <h5>{{ra.program.dj.brand}}</h5>
              </div>
            </div>
          </i-col>
        </Row>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Footer from '../footer/Footer'
import Header from '../Header/Header'
import BackTop from '../backtop/src/main'
import {getBanner, recommendSong, getSole, reNewSong, recommendMV, radioStation} from '../../api/node'
import {saveSongId, saveSongName, saveSingerName, saveSongUrl} from '../../api/storage'

export default {
  name: 'PageOne',
  data () {
    return {
      keyword: '',
      banner: [],
      result: [], // 推荐歌单
      soleArr: [], // 独家放送
      newSong: [], // 推荐新歌
      mvarr: [], // 推荐mv
      radioArr: [] // 主播电台
    }
  },
  created () {
    // banner
    getBanner().then(res => {
      // console.log(res)
      if (res.code === 200) {
        this.banner = res.banners
      }
    })
    // 推荐歌单
    recommendSong().then(res => {
      if (res.code === 200) {
        this.result = res.result.slice(0, 6)
        // console.log(this.result)
      }
    })
    // 独家放送
    getSole().then(res => {
      if (res.code === 200) {
        this.soleArr = res.result
        // console.log(this.soleArr)
      }
    })
    // 推荐新歌
    reNewSong().then(res => {
      if (res.code === 200) {
        this.newSong = res.result
        // console.log(this.newSong)
      }
    })
    // 推荐mv
    recommendMV().then(res => {
      // console.log(res)
      if (res.code === 200) {
        this.mvarr = res.result
        // console.log(this.mvarr)
      }
    })
    // 主播电台
    radioStation().then(res => {
      // console.log(res)
      if (res.code === 200) {
        this.radioArr = res.result
        // console.log(this.radioArr)
      }
    })
  },
  methods: {
    searchClick () {
      this.$router.push('/searchSong')
    },
    goDetail (id) {
      this.$router.push('/songDetail/' + id)
    },
    goSongPlay (id, sname, name, url) {
      saveSongId(id)
      saveSongName(sname)
      saveSingerName(name)
      saveSongUrl(url)
      this.$router.push('/songPlay2')
    }
  },
  components: {
    Header,
    Footer,
    BackTop
  }
}
</script>

<style lang="scss" scoped>
.page-one{
  width: 100%;
  padding-top: 50px;
  padding-bottom: 50px;
  /*banner*/
  .swiper-box {
    height: 160px;
    padding-top: 40px;
    .mint-swipe {
      width: 100%;
      height: 160px;
      color: #fff;
      font-size: 30px;
      text-align: center;
      .mint-swipe-item {
        img {
          width: 100%;
          height: 160px;
          position: relative;
        }
        .lable{
          position: absolute;
          bottom: 10px;
          z-index: 22;
          right: 0;
          width: 60px;
          height: 20px;
          border-top-left-radius: 10px;
          border-bottom-left-radius: 10px;
          text-align: center;
          color: #fff;
          font-size: 12px;
          line-height: 20px;
          opacity: 0.8;
        }
      }
    }
  }
  /*搜索*/
  .plot-wrapper{
    width: 100%;
    background: #fff;
    .search {
      width: 100%;
      position: fixed;
      top: 50px;
      left: 0;
      background-color: #fff;
      text-align: center;
      height: 44px;
      line-height: 44px;
      z-index: 30;
      .search-wrapper {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        width: 92%;
        margin: 0 10px;
        border-radius: 4px;
        background-color: #e6e6e6;
        input {
          width: 118px;
          font-size: 14px;
          outline: none;
          border: none;
          background-color: #e6e6e6;
          &::-ms-input-placeholder {
            text-align: center;
          }
          &::-webkit-input-placeholder {
            text-align: center;
          }
        }
        .search-icon {
          display: inline-block;
          width: 17px;
          height: 17px;
          vertical-align: middle;
        }

      }
    }
  }
  /*推荐歌单*/
  .recommend-songs{
    width: 100%;
    padding: 50px 10px 10px 10px;
    .recommend-title{
      height: 30px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #f2f2f2;
      padding-bottom: 10px;
      justify-content: space-between;
      .title-left{
        display: inline-flex;
        align-items: center;
        span{
          font-size: 15px;
          padding-left: 10px;
          color: #333;
        }
      }
      span{
        color: #999;
        font-size: 12px;
      }
    }
    .song_box{
      width: 100%;
      padding: 0 10px;
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      .sudoku_item{
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        width: 33.3333%;
        /*height: 170px;*/
        padding: 5px;
        position: relative;
        .song_number{
          width: 91%;
          height: 26px;
          background:#000;
          position: absolute;
          top: 5px;
          opacity: 0.5;
          text-align: right;
          span{
            color: #fff;
            font-size: 10px;
            line-height: 26px;
            margin-right: 10px;
          }
        }
        .song_img{
          width: 100%;
          height: 100px;
          background: url("../../assets/logo.png") no-repeat;
          background-size: 100% 100%;
        }
        .song_text{
          width: 100%;
          /*height: 50px;*/
          p{
            font-size: 12px;
            margin-top: 5px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }
  }
  /*独家放送*/
  .sole-send{
    width: 100%;
    padding: 10px;
    .sole-title{
      height: 30px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #f2f2f2;
      padding-bottom: 10px;
      justify-content: space-between;
      .title-left{
        display: inline-flex;
        align-items: center;
        span{
          font-size: 15px;
          padding-left: 10px;
          color: #333;
        }
      }
      span{
        color: #999;
        font-size: 12px;
      }
    }
    .album{
      padding-top: 10px;
      .ivu-row{
        margin-left: 0 !important;
        margin-right: 0 !important;
      }
      .ivu-col-span-12 {
        padding-bottom: 20px;
        .grid_div{
          text-align: center;
          height: 70px;
          background-size: 100% 100%;
          position: relative;
          .video-num{
            /*width: 60px;*/
            height: 20px;
            background: rgba(0,0,0,0.5);
            position: absolute;
            right: 0;
            img{
              width: 20px;
              float: left;
            }
            span{
              color: #fff;
              float: left;
              line-height: 20px;
              padding-left: 10px;
              padding-right: 5px;
            }
          }
        }
        h3{
          font-weight: normal;
          font-size: 15px;
          padding-top: 10px;
          color: #000;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
  /*最新音乐*/
  .new-song{
    width: 100%;
    padding: 10px;
    .new-title{
      height: 30px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #f2f2f2;
      padding-bottom: 10px;
      justify-content: space-between;
      .title-left{
        display: inline-flex;
        align-items: center;
        span{
          font-size: 15px;
          padding-left: 10px;
          color: #333;
        }
      }
      span{
        color: #999;
        font-size: 12px;
      }
    }
    .new-album{
      padding-top: 10px;
      .ivu-row{
        margin-left: 0 !important;
        margin-right: 0 !important;
      }
      .ivu-col-span-12 {
        padding-bottom: 20px;
        .song{
          display: flex;
          align-items: center;
          .index-num{
            width: 15px;
            p{
              font-size: 15px;
            }
          }
          img{
            width: 55px;
            height: 55px;
            border: 1px solid #999;
            padding: 2px;
          }
          .song-name{
            padding-left: 10px;
            width: 100px;
            h4{
              font-size: 15px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
            h5{
              font-weight: normal;
            }
          }
        }
      }
    }
  }
  /*推荐mv*/
  .recommend-MV{
    width: 100%;
    padding: 10px;
    .mv-title{
      height: 30px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #f2f2f2;
      padding-bottom: 10px;
      justify-content: space-between;
      .title-left{
        display: inline-flex;
        align-items: center;
        img{
          width: 25px;
        }
        span{
          font-size: 15px;
          padding-left: 10px;
          color: #333;
        }
      }
      span{
        color: #999;
        font-size: 12px;
      }
    }
    .mv-album{
      padding-top: 10px;
      .ivu-row{
        margin-left: 0 !important;
        margin-right: 0 !important;
      }
      .ivu-col-span-12 {
        padding-bottom: 20px;
        .grid_div{
          text-align: center;
          height: 90px;
          background-size: 100% 100%;
          position: relative;
          .video-num{
            /*width: 60px;*/
            height: 20px;
            background: rgba(0,0,0,0.5);
            position: absolute;
            right: 0;
            display: flex;
            align-items: center;
            span{
              color: #fff;
              float: left;
              line-height: 20px;
              padding-left: 10px;
              padding-right: 5px;
            }
          }
        }
        h3{
          font-weight: normal;
          font-size: 15px;
          padding-top: 10px;
          color: #000;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        p{
          font-size: 12px;
          color: #999;
        }
      }
    }
  }
  /*主播电台*/
  .radio-station{
    width: 100%;
    padding: 10px;
    .radio-title{
      height: 30px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #f2f2f2;
      padding-bottom: 10px;
      justify-content: space-between;
      .title-left{
        display: inline-flex;
        align-items: center;
        img{
          width: 25px;
        }
        span{
          font-size: 15px;
          padding-left: 10px;
          color: #333;
        }
      }
      span{
        color: #999;
        font-size: 12px;
      }
    }
    .radio-album{
      padding-top: 10px;
      .ivu-row{
        margin-left: 0 !important;
        margin-right: 0 !important;
      }
      .ivu-col-span-12 {
        padding-bottom: 20px;
        .song{
          display: flex;
          align-items: center;
          img{
            width: 55px;
            height: 55px;
            border: 1px solid #999;
            padding: 2px;
          }
          .song-name{
            padding-left: 10px;
            width: 100px;
            h4{
              font-size: 15px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
            h5{
              font-weight: normal;
            }
          }
        }
      }
    }
  }
}
</style>
